<?php

namespace mpend\modules\cms\models;

use Yii;
use common\models\cms\CmsArticleStats;

/**
 * 资讯模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ArticleView extends \common\models\cms\CmsArticle {

    public function afterFind() {
        parent::afterFind();
        $stats = CmsArticleStats::findOrNew([
            'article_id' => $this->id,
        ]);
        $stats->views += 1;
        $stats->save(false);
    }

   

    public function fields() {
        return [
            'id',
            'title',
            'description',
            'format',
            'thumb' => 'thumbUrl',
            'channel',
            'album',
            'video',
            'stats',
            'data',
            'from',
            'authorText',
            'publishTime',
            'liked',
        ];
    }

}
